public class Solve {

    public static void main(String[] args) {
        Solve solve = new Solve();
        char[][] board= {{'O', 'O'}, {'O', 'O'}};
        solve.solve(board);
        System.out.println(board);
    }

    public void solve(char[][] board) {
        int m = board.length;
        int n = board[0].length;
        boolean[][] ban = new boolean[m][n];
        for (int i = 0; i < n; i++) {
            ban(ban, board, 0, i, m, n);
            ban(ban, board, m - 1, i, m, n);
        }
        for (int i = 1; i < m - 1; i++) {
            ban(ban, board, i, 0, m, n);
            ban(ban, board, i, n - 1, m, n);
        }
        for (int i = 1; i < m - 1; i++) {
            for (int j = 1; j < n - 1; j++) {
                if (!ban[i][j] && board[i][j] == 'O') board[i][j] = 'X';
            }
        }
    }

    public void ban(boolean[][] ban, char[][] board, int i, int j, int m, int n) {
        if (i < 0 || i >= m || j < 0 || j >= n || board[i][j] == 'X' || ban[i][j]) return;
        ban[i][j] = true;
        ban(ban, board, i + 1, j, m, n);
        ban(ban, board, i - 1, j, m, n);
        ban(ban, board, i, j + 1, m, n);
        ban(ban, board, i, j - 1, m, n);
    }
}
